package com.huawei.hms.auth.api.signin.internal;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import com.huawei.hms.api.Api;
import com.huawei.hms.api.HuaweiApiAvailability;
import com.huawei.hms.auth.api.signin.HuaweiIdSignInClient;
import com.huawei.hms.auth.api.signin.internal.c.a;
import com.huawei.hms.common.ApiException;
import com.huawei.hms.common.HuaweiApi;
import com.huawei.hms.support.api.client.Status;
import com.huawei.hms.support.api.entity.hwid.HuaweiIdSignInRequest;
import com.huawei.hms.support.api.entity.hwid.HwIDNaming;
import com.huawei.hms.support.api.entity.hwid.SignOutReq;
import com.huawei.hms.support.api.hwid.HuaweiIdSignInOptions;
import com.huawei.hms.support.api.hwid.SignInHuaweiId;
import com.huawei.hms.support.hianalytics.HiAnalyticsClient;
import com.huawei.hms.support.log.HMSLog;
import o.fjo;
import o.fjx;
import org.json.JSONException;

public class e extends HuaweiApi<HuaweiIdSignInOptions> implements HuaweiIdSignInClient {
    private static final Api<HuaweiIdSignInOptions> a = new Api(HuaweiApiAvailability.HMS_API_NAME_ID);

    public e(Activity activity, HuaweiIdSignInOptions huaweiIdSignInOptions) {
        super(activity, a, huaweiIdSignInOptions, new c());
        setKitSdkVersion(a.a());
    }

    public e(Context context, HuaweiIdSignInOptions huaweiIdSignInOptions) {
        super(context, a, huaweiIdSignInOptions, new c());
        setKitSdkVersion(a.a());
    }

    public Intent getSignInIntent() {
        return i.a(getContext(), (HuaweiIdSignInOptions) getOption(), getSubAppID());
    }

    public fjo<Void> signOut() {
        i.a();
        return doWrite(new g(HwIDNaming.signout, new SignOutReq().toJson()));
    }

    public fjo<SignInHuaweiId> silentSignIn() {
        HMSLog.i("[HUAWEIIDSDK]HuaweiIdSignInClient", "silentSignIn");
        HuaweiIdSignInRequest huaweiIdSignInRequest = new HuaweiIdSignInRequest();
        huaweiIdSignInRequest.setHuaweiIdSignInOptions((HuaweiIdSignInOptions) getOption());
        try {
            return doWrite(new f(HwIDNaming.silentSignIn, huaweiIdSignInRequest.toJson(), HiAnalyticsClient.reportEntry(getContext(), HwIDNaming.silentSignIn, a.a())));
        } catch (JSONException e) {
            HMSLog.e("[HUAWEIIDSDK]HuaweiIdSignInClient", 2015, "JSONException");
            fjx o_fjx = new fjx();
            o_fjx.ॱ(new ApiException(new Status(2015)));
            return o_fjx.ॱ();
        }
    }

    public fjo<Void> revokeAccess() {
        HuaweiIdSignInRequest huaweiIdSignInRequest = new HuaweiIdSignInRequest();
        huaweiIdSignInRequest.setHuaweiIdSignInOptions((HuaweiIdSignInOptions) getOption());
        try {
            return doWrite(new d(HwIDNaming.revokeAccess, huaweiIdSignInRequest.toJson(), HiAnalyticsClient.reportEntry(getContext(), HwIDNaming.revokeAccess, a.a())));
        } catch (JSONException e) {
            HMSLog.e("[HUAWEIIDSDK]HuaweiIdSignInClient", 2015, "JSONException");
            fjx o_fjx = new fjx();
            o_fjx.ॱ(new ApiException(new Status(2015)));
            return o_fjx.ॱ();
        }
    }
}
